import json
import os
basic_path = str(os.path.dirname(__file__)) + "\\"
detail_path = basic_path + "..\\..\\school_detail\\school_detail.json"

# 打开 JSON 文件
with open(detail_path, 'r', encoding='utf-8') as f:
    data = json.load(f)

# 现在，data 是一个包含 JSON 数据的字典或列表

json_update = {}

for key, value in data.items():
    print(key)
    print(value['name'])
    school_class = ''
    if value['f985'] == '1':
        school_class += '1'
    if value['f211'] == '1':
        school_class += '2'
    if value['dual_class_name'] == '双一流':
        school_class += '3'
    if value['f985'] != '1' and value['f211'] != '1' and value['dual_class_name'] != '双一流':
        school_class = '4'

    json_update[key] = {'name': value['name'], 'province': value['province_name'], 'city': value['city_name'],
                        'school_class': school_class}

# 打开一个文件并写入 JSON 数据
with open('json/schoolBasic.json', 'w', encoding='utf-8') as f:
    json.dump(json_update, f, ensure_ascii=False, indent=4)